/**   
 * @Title: MyInterceptor.java 
 * @Package com.dragon.learn.interceptors 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author dragon   
 * @date 2018年8月21日 下午11:17:51 
 * @version V1.0   
 */
package com.dragon.learn.interceptors;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** 
 * @ClassName: MyInterceptor 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author dragon
 * @date 2018年8月21日 下午11:17:51 
 *  
 */
public class MyInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		
		long starttime = System.currentTimeMillis();
		
		request.setAttribute("starttime", starttime);
		return true;
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
		long starttime = (long) request.getAttribute("starttime");
		long currenttime = System.currentTimeMillis();
		System.out.println("##########################");
		System.out.println("##########################");
		System.out.println("##########################");
		System.out.println("handler:" + handler);
		System.out.println("ex:" + ex);
		long hadelTime = currenttime - starttime;
		System.out.println("处理时间:" + hadelTime+ " ms");
		request.setAttribute("hadelTime", hadelTime);
		System.out.println("##########################");
		System.out.println("##########################");
		System.out.println("##########################");
	}
}
